﻿<?php
require_once dirname(__FILE__).'/AdminOnlyPageHeader.php';

$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx = 1;

$searchField = isset($_GET['searchField']) ? $_GET['searchField'] : ''; 
$searchOper = isset($_GET['searchOper']) ? $_GET['searchOper']: '';  
$searchString = isset($_GET['searchString']) ? $_GET['searchString'] : '';
/*
if($searchField)
{
	var_dump($searchField, $searchOper, $searchString); die;
}
*/
$objRsp = FetchAllUsers($limit, $page, $sidx, $sord, $searchField, $searchOper, $searchString);
$xmlRsp = "<?xml version='1.0' encoding='utf-8'?>";
$xmlRsp .= "<rows>";
$xmlRsp .=    "<page>".$objRsp->page."</page>";
$xmlRsp .=    "<total>".$objRsp->total."</total>";
$xmlRsp .=    "<records>".$objRsp->records."</records>";

foreach ($objRsp->rows as $row)
{
//if($row['eMail']=="gbukauskas@gmail.com")	
//	var_dump($row['eMail']);
//	var_dump((bool)$row['IsAdmin']);
	
    $xmlRsp .= "<row id='". $row['eMail']."'>";
    $xmlRsp .=    "<cell>". $row['eMail']."</cell>";
    $xmlRsp .=    "<cell><![CDATA[". $row['Name']."]]></cell>";
	if($row['IsActive'])
		$xmlRsp .= "<cell></cell>";
	else
    	$xmlRsp .= "<cell>Ne</cell>";
	if ($row['IsAdmin'])
    	$xmlRsp .= "<cell>Taip</cell>";
	else
		$xmlRsp .= "<cell></cell>";
    $xmlRsp .=    "<cell><![CDATA[".GetPersonRoles($row['eMail'])."]]></cell>";
    $xmlRsp .= "</row>";
}
//die;
$xmlRsp .=  "</rows>";

//var_dump('00', $xmlRsp);die;
header("Content-type: text/xml;charset=utf-8");
echo $xmlRsp;
?>